/*
 * OpenSCAD File with the code to draw a part of the quadcopter in 3D
 * Part Number: 04
 * Version: 0.01
 * Units: mm
 * Last Modification: Sun Jun 27 23:20:26 WEST 2010
 *
 * Copyright (C) 2010 Henrique Dias <henrique.ribeiro.dias@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

// hole=29.82
frominclude = 0;

p4_ringcenter=31.82;
p4_cylinderwidth=1+p4_ringcenter+p4_ringcenter+1;
p4_distance=p4_ringcenter/sqrt(2);

module p4_subcomponent()
{
	for (pos = [[90,0,0], [-90,0,0], [0,90,0],[0,-90,0]]) {
		rotate(a=pos) {
			translate(v = [0, 0, ((p4_ringcenter+1+1-4)/2)+4]) {
				cylinder(h=p4_ringcenter+1+1-4, r=2, center=true, $fn=60);
			}
		}
	}
	cylinder(h=10, r=1.5, center=true, $fn=60);
	translate(v = [0, 0, 3.5]) {
		cylinder(h=2, r=2.5, center=true, $fn=60);
	}
	for (pos = [[p4_distance, p4_distance, 0], [-p4_distance, p4_distance, 0], [p4_distance, -p4_distance, 0], [-p4_distance, -p4_distance, 0]]) {
		translate(v = pos) {
			cylinder(h=8, r=1.5, center=true, $fn=60);
		}
	}
	for (pos = [[p4_distance, p4_distance, 3.5], [-p4_distance, p4_distance, 3.5], [p4_distance, -p4_distance, 3.5], [-p4_distance, -p4_distance, 3.5]]) {
		translate(v = pos) {
			cylinder(h=2, r=2.5, center=true, $fn=60);
		}
	}
	for (angle = [p4_distance,p4_distance+45,p4_distance+90,p4_distance+90+45,-p4_distance,-p4_distance-45,-p4_distance-90,-p4_distance-90-45]) {
		rotate(a=[0,90,angle]) {
			translate(v = [0, 0, p4_ringcenter]) {
				cylinder(h=3.5, r=1.25, center=true, $fn=60);
			}
		}
	}
}

module p4_addcomponent()
{
	rotate(a=[0,90,0]) {
		cylinder(h=p4_cylinderwidth, r=4, center=true, $fn=60);
		cube(size = [8, 2, p4_cylinderwidth], center=true);
	}
	rotate(a=[90,0,0]) {
		cylinder(h=p4_cylinderwidth, r=4, center=true, $fn=60);
		cube(size = [2, 8, p4_cylinderwidth], center=true);
	}
	rotate(a=[0,0,90]) {
		difference() {
			cylinder(h=8, r=p4_ringcenter+1, center=true, $fn=120);
			cylinder(h=8, r=p4_ringcenter-1, center=true, $fn=120);
		}
	}
	cylinder(h = 8, r=5.66, center=true, $fn=60);

	for (pos = [[p4_distance, p4_distance, 0],[p4_distance, -p4_distance, 0],[-p4_distance, p4_distance, 0],[-p4_distance, -p4_distance, 0]]) {
		translate(v = pos) {
			cylinder(h=8, r=3.5, center=true, $fn=60);
		}
	}
	for (angle = [p4_distance,p4_distance+45,p4_distance+90,p4_distance+90+45,-p4_distance,-p4_distance-45,-p4_distance-90,-p4_distance-90-45]) {
		rotate(a=[0,90,angle]) {
			translate(v = [0, 0, p4_ringcenter]) {
				cylinder(h=2.5, r=2.25, center=true, $fn=60);
			}
		}
	}
}

module part04()
{
	difference() {
		union() {
			p4_addcomponent();
		}
		p4_subcomponent();
	}
}

if(frominclude == 0) {
	part04();
}